package com.thinkgem.jeesite.common.utils;

import com.thinkgem.jeesite.modules.lottery.entity.Lottery;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;
import org.web3j.tx.gas.ContractGasProvider;
import org.web3j.tx.gas.DefaultGasProvider;

import java.util.List;

public class LotteryContractUtils {
    private static Lottery connect(){
        Web3j web3 = Web3j.build(new HttpService("http://localhost:7545"));
        String contractAddress = "0xbE909Edd5CaC106B1bB13064DA7d31efc33DE8C3";
        String privateKey = "ea4c0eabb77535415f0c0e9e11451f566129aac35c5acab8967f024f48413125";
        Credentials dummyCredentials = Credentials.create(privateKey);
        ContractGasProvider contractGasProvider = new DefaultGasProvider();
        Lottery contract =Lottery.load(contractAddress,web3,dummyCredentials,contractGasProvider);
        return contract;
    }
    public static void record(String activityId,String openid) throws Exception{
        Lottery contract = connect();
        contract.participate(activityId,openid).send();
    }
}
